Skip to content

migrate: convert strings.ipynb from pandas to polars - #12

Merged
brentomagic merged 4 commits into
mainfrom
strings-conversion-to-polars
Jul 29, 2026
Merged

migrate: convert strings.ipynb from pandas to polars#12
brentomagic merged 4 commits into
mainfrom
strings-conversion-to-polars

Conversation

@meshackamadi

Copy link
Copy Markdown
Collaborator

Summary

Converts the strings.ipynb chapter from pandas to polars, covering string manipulation and text processing.

Changes

Code

  • pd.Series()pl.Series()
  • .str.lower().str.to_lowercase()
  • .str.upper().str.to_uppercase()
  • .str.title().str.to_titlecase()
  • .str.extract().str.extract()
  • .str.split(expand=True).list.to_struct().unnest()

Text

  • Updated prerequisites to mention polars
  • Updated string method references to polars equivalents
  • Removed pandas-specific documentation links

Testing

  • All code blocks execute successfully
  • String operations produce expected results
  • Notebook renders without errors

Files Modified

  • strings.ipynb

@meshackamadi
meshackamadi requested a review from ugohuche July 17, 2026 15:11
@meshackamadi
meshackamadi requested a review from brentomagic July 27, 2026 19:08

@brentomagic brentomagic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the strings migration — prerequisites, method table, to_titlecase / to_lowercase, extract, and the splitlist.to_struct().unnest() pattern look good, and CI is green. A few fixes before merge:

Must-fix

  1. Lost “last token after split” example
    Original taught split().str.get(-1) (last name). That was replaced with:

    df.with_columns(pl.col("names").str.slice(0, 5))

    which teaches something different. Please restore the last-token idea with polars list access, e.g.:

    df.with_columns(pl.col("names").str.split(" ").list.get(-1).alias("last"))

    Keep a slice() example if you want, but don’t drop the split→get teaching point.

  2. get_dummies → column split needs clearer prose
    Original str.get_dummies(";") produced one-hot indicator columns. The new code:

    .str.split("; ").list.to_struct(...).unnest("tags")

    splits into fixed country / subject columns instead. That’s fine for this dataset, but the text should say so explicitly (and not imply it’s the same as dummy encoding). Optionally show a polars-native dummy approach later (explode + pivot / to_dummies) if you want to keep that skill.

Medium / nits

  1. Grammar: “we can use the `str.split()` to split” → “use `str.split()` …”
  2. Kernelspec display_name: ".venv" → generic Python 3 (ipykernel) (same note as other PRs).
  3. Commit author metadata is still Your Name — please set git user.name/email for future commits.

Happy to approve after the last-token example (and clearer dummies→split prose) are sorted.

Show both str.slice and split().list.get(-1), and clarify fixed-field splitting versus dummy encoding.

Co-authored-by: Cursor <cursoragent@cursor.com>
@brentomagic
brentomagic self-requested a review July 29, 2026 11:02
@brentomagic
brentomagic merged commit cb0ff3f into main Jul 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants